//
//  MCPickNumberViewController.m
//  TLYL
//
//  Created by miaocai on 2017/6/7.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCPickNumberViewController.h"
#import "MCLotteryHalllPickTableViewCell.h"
#import "MCLotteryHalllPickTableViewModel.h"
#import "UIImage+Extension.h"
#import "MCBallCollectionModel.h"
#import "MCPaySelectedLotteryTableViewController.h"
#import "MCPullMenuViewController.h"
#import "MCLotteryRecordView.h"
#import "MCRandomUntits.h"
#import "MCPaySelectedLotteryModel.h"
#import "MCLotteryRecordViewController.h"
#import "MCPullMenuPresentationController.h"
#import "MCLotteryDrawDetailsViewController.h"
#import "MCMaxbonusModel.h"
#import "ExceptionView.h"
#import "MCHistoryIssueDetailAPIModel.h"
#import "MCMMCNewViewController.h"
#import "MCMMCPresentationController.h"
#import "MCDataTool.h"
#import "MCBetModel.h"
#import "MCPopAlertView.h"
#import "MCGameRecordViewController.h"
#import "MCUserMoneyModel.h"
@interface MCPickNumberViewController ()<UITableViewDataSource,UITableViewDelegate>

#pragma mark -property

///**分组保存选中的号码球*/
//@property (nonatomic,strong) NSMutableArray *selectedArrary;
/**随机数*/
@property (nonatomic,strong) NSMutableArray *randomBallArray;
/**cell强引用*/
@property (nonatomic,strong) NSMutableArray *cellArray;

@property (nonatomic,assign)CGFloat height_Footer;

@property (nonatomic,strong)UIView * view_footer;
/**该彩种开奖号码记录API*/
@property (nonatomic,strong)MCHistoryIssueDetailAPIModel * historyIssueDetailAPIModel;
/**该彩种开奖记录占位图*/
@property (nonatomic,strong)ExceptionView * exceptionView;
/**清除按钮被点击-------发出通知优化*/
@property (nonatomic,assign,getter=isClearAllNumber) BOOL clearAllNumber;
/**无期号*/
@property (nonatomic,strong) UIView * noIssueNumberView;
/**单期标记*/
@property (nonatomic,assign) BOOL danQiNotiShowed;

@property (nonatomic,assign) BOOL isHadChanged;

@property (nonatomic,assign) BOOL isStopMoving;
/**添加号码的小红点数字*/
@property (nonatomic,weak) UILabel *addItemLabel;
@property (nonatomic,strong) MCBetModel *betModel;
@property (nonatomic,strong) MCUserMoneyModel * userMoneyModel;
@property (nonatomic,assign,getter=isRequsting) BOOL requsting;
@end

@implementation MCPickNumberViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.baseWFmodel.czName) {
        self.navigationItem.title = self.baseWFmodel.czName;
    }
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
   _isHadChanged=NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mcTableView_height:) name:PickViewControllerChangeFooterHeightNSNotification object:nil];
    _height_Footer=0.0001;
    /*
     * 初始化 小圆点
     */
    MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
    if (model.dataSource.count>0) {
        self.addItemLabel.text = [NSString stringWithFormat:@"%d",(int)model.dataSource.count];
        self.addItemLabel.hidden = NO;
    }else{
        self.addItemLabel.hidden = YES;
    }
    
    self.danQiNotiShowed = NO;
//    if (self.isDanShi) {
//        [self.alertView showStackWindow];
//    }
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cleanWBtnClickNotification) name:@"cleanWBtnClickNotification" object:nil];
}
/*
 * 一键清空单式
 */

- (void)cleanWBtnClickNotification{
    [self clearData];
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}
- (void)dealloc{
    [self.cellArray removeAllObjects];
   
}

/*
 * 每次重置菜种
 */
-(void)MC_PICKNUMBERVC_INIT{
  
    
    typeof(self) weakSelf = self;
    //每次重置菜种tableView滑到顶端
    if (weakSelf.baseTableView) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [weakSelf.baseTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
    }
    //cellArray  add的方法始终在此方法后面
    if (weakSelf.cellArray.count==weakSelf.baseWFmodel.item.count) {
        [weakSelf clearData];
    }
    
 
}

//- (void)showStackWindow{
//    self.baseTableView.contentInset = UIEdgeInsetsMake(0, 0,  20, 0);
//}
//- (void)hidenStackWindow{
//    self.baseTableView.contentInset = UIEdgeInsetsMake(0, 0,  20, 0);
//}
#pragma mark - setUpUI
- (void)setUpUI{

    self.view.backgroundColor = RGB(239, 239, 239);
    /**tabView 创建*/
    UITableView *tab = [[UITableView alloc] initWithFrame:CGRectMake(0, MC_REALVALUE(40), G_SCREENWIDTH, G_SCREENHEIGHT - 64) style:UITableViewStyleGrouped];
    [self.view addSubview:tab];
    tab.delegate = self;
    tab.dataSource = self;
    tab.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.baseTableView = tab;
    self.baseTableView.backgroundColor=RGB(239, 239, 239);
    if (G_SCREENHEIGHT<500) {
        self.baseTableView.estimatedRowHeight = 10;
    } else if(G_SCREENHEIGHT<600){
        self.baseTableView.estimatedRowHeight = 40;
    }else{
        self.baseTableView.estimatedRowHeight = 50;
    }
    if (@available(iOS 11.0, *)) {
        self.baseTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.baseTableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
    [self setUpDragShoppingCarBtn];
//    [self.view  insertSubview:self.noIssueNumberView belowSubview:self.baseTableView];
//    self.noIssueNumberView.frame=CGRectMake(0, 0, G_SCREENWIDTH, HEIGHTnoIssueView);
    
    //创建手势对象
//    UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self     action:@selector(tapAction:)];
//    tap.numberOfTapsRequired =1;
//    [self.noIssueNumberView addGestureRecognizer:tap];
    
}
//-(void)tapAction:(UITapGestureRecognizer*)recognizer{
//
//    [super loadIssueData:^(BOOL result) {
//        if (result) {
//            [UIView animateWithDuration:0.4 animations:^{
//
//                self.baseTableView.transform = CGAffineTransformIdentity;
//                self.btnDaojishi.transform = CGAffineTransformIdentity;
//                self.btnPCatergy.transform = CGAffineTransformIdentity;
//                self.btnKaiJiang.transform = CGAffineTransformIdentity;
//
//            } completion:^(BOOL finished) {
//                self.baseTableView.frame = CGRectMake(0, HEIGHTDAOJISHI+HEIGHTKAIJIANGHAO, G_SCREENWIDTH, G_SCREENHEIGHT - (HEIGHTDAOJISHI+HEIGHTKAIJIANGHAO)- 49-44);
//            }];
//        }
//
//    }];
//
//}

//-(UIView *)noIssueNumberView{
//    if (!_noIssueNumberView) {
//        _noIssueNumberView=[[UIView alloc]init];
//        _noIssueNumberView.backgroundColor=RGB(238, 198, 198);
//        UIImageView * img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"noIssue_icon"]];
//        [_noIssueNumberView addSubview:img];
//        img.frame=CGRectMake(10, (HEIGHTnoIssueView-14)/2.0, 14, 14);
//        UILabel * lab=[[UILabel alloc]init];
//        lab.text=@"获取期号失败，请稍后再试。（点击刷新）";
//        [_noIssueNumberView addSubview:lab];
//        lab.font=[UIFont systemFontOfSize:12];
//        lab.textAlignment=NSTextAlignmentLeft;
//        lab.frame=CGRectMake(34, 0, G_SCREENWIDTH, HEIGHTnoIssueView);
//        lab.textColor=[UIColor redColor];
//    }
//    return _noIssueNumberView;
//}

#pragma mark -------------------------------- Drag ShoppingCar Btn
- (void)setUpDragShoppingCarBtn{
    
    UIButton *btn = [[UIButton alloc] init];
    [self.view addSubview:btn];
    btn.frame = CGRectMake(20, G_SCREENHEIGHT - 260, 50, 50);
    [btn setBackgroundImage:[UIImage imageNamed:@"gowuche"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"gowuche"] forState:UIControlStateHighlighted];
    UIPanGestureRecognizer *longPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(longP:)];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
//    [btn addTarget:self action:@selector(dragMoving:withEvent: )forControlEvents: UIControlEventTouchDragInside];
//
//    [btn addTarget:self action:@selector(btnClickTouchUpInside )forControlEvents: UIControlEventTouchDownRepeat];
//
    [btn addGestureRecognizer:longPan];
    [btn addGestureRecognizer:tap];
    
    [self.view addSubview:btn];
    
    
    
    UILabel *addItemCountLabel = [[UILabel alloc] init];
    addItemCountLabel.text = @"99+";
    [btn addSubview:addItemCountLabel];
    addItemCountLabel.backgroundColor = [UIColor whiteColor];
    addItemCountLabel.layer.cornerRadius = MC_REALVALUE(7);
    addItemCountLabel.layer.masksToBounds = YES;
    addItemCountLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(9)];
    
    addItemCountLabel.textAlignment = NSTextAlignmentCenter;
    addItemCountLabel.hidden = YES;
    addItemCountLabel.textColor =RGB(249, 83, 85);//[UIColor whiteColor];
    self.addItemLabel = addItemCountLabel;
    [addItemCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(btn.mas_right).offset(-MC_REALVALUE(10));
        make.top.equalTo(btn.mas_top).offset(MC_REALVALUE(10));
        make.height.equalTo(@(MC_REALVALUE(14)));
        make.width.equalTo(@(MC_REALVALUE(14)));
    }];
    
}

-(void)longP:(UIPanGestureRecognizer *)rec{
    //返回在横坐标上、纵坐标上拖动了多少像素
    
    CGPoint point=[rec translationInView:self.view];
    
    rec.view.center=CGPointMake(rec.view.center.x+point.x, rec.view.center.y+point.y);
    if (rec.view.center.x < MC_REALVALUE(0) ) {
        rec.view.center = CGPointMake(0,  rec.view.center.y+point.y);
    }
    if (rec.view.center.x > G_SCREENWIDTH ) {
        rec.view.center = CGPointMake(G_SCREENWIDTH,  rec.view.center.y+point.y);
    }
    if (rec.view.center.y < MC_REALVALUE(115) ) {
       rec.view.center = CGPointMake(rec.view.center.x+point.x, MC_REALVALUE(115));
    }
    if (rec.view.center.y > MC_REALVALUE(510)) {
        rec.view.center = CGPointMake(rec.view.center.x+point.x, MC_REALVALUE(510));
    }
    
    [rec setTranslation:CGPointMake(0, 0) inView:self.view];
    
}
- (void)tap:(UITapGestureRecognizer *)tap{
    [self payTheSelectedNumbers];
}


#pragma mark ------ UITableViewDataSource And UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if ([self.baseWFmodel.lineCount  isEqualToString: @""]) {
        return 0;
    } else {
        if ([self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {//单式
            return 1;
        } else {
            return [self.baseWFmodel.lineCount intValue];
        }
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *Identifier = [NSString stringWithFormat:@"MCLotteryHalllPickTableViewCell%ld",(long)indexPath.row];
    
    MCLotteryHalllPickTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    
    if (cell == nil) {
        cell = [[MCLotteryHalllPickTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
    }
    cell.index = indexPath.row;
    self.baseWFmodel.index = indexPath.row;
    if (![self.cellArray containsObject:cell]) {
        [self.cellArray addObject:cell];
    }
    __weak typeof(self)weakSelf = self;
    cell.lotteriesType = self.lotteriesTypeModel.LotteryID;
    cell.headerCardSelectedBlock = ^(MCPickNumberHeaderViewType Type, NSString *content) {
        if (Type == MCPickNumberHeaderView_Add) {
            [weakSelf.selectedCardArray addObject:content];
        } else {
            [weakSelf.selectedCardArray removeObject:content];
        }
        weakSelf.baseWFmodel.selectedCardArray = weakSelf.selectedCardArray;
        
        /*
         * 注数计算
         */
        //非单式注数计算
        MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
        
        //单式注数计算
        MCLotteryHalllPickTableViewCell *cell=[self.baseTableView  cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        [cell caculateStakeNumber];
    };
    cell.selectedCardArrayBlock = ^(NSMutableArray *selectedCardArray) {
        weakSelf.baseWFmodel.selectedCardArray = selectedCardArray;
        weakSelf.selectedCardArray = selectedCardArray;
    };
    if (![self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {//非单式
        //每个cell对应的说明信息和小图标
        cell.dataSource = self.baseWFmodel.item[indexPath.row];
       
        
        __weak MCLotteryHalllPickTableViewCell *weakcell = cell;
        
        __weak typeof(self) weakSelf = self;
        //号码球状态改变
        cell.slectedBallBlock = ^(NSMutableArray *arr){
           //当前cell的的内容
            weakcell.baseSlectedModel.selectedArray = arr;
            //当前cell的index
            weakcell.baseSlectedModel.index = (int)indexPath.row;
            //分组后的封装
            if (![weakSelf.selectedArrary containsObject:weakcell.baseSlectedModel] && arr.count != 0 ) {
                
                [weakSelf.selectedArrary addObject:weakcell.baseSlectedModel];
                
            }else if ([weakSelf.selectedArrary containsObject:weakcell.baseSlectedModel] && arr.count == 0){
                [weakSelf.selectedArrary removeObject:weakcell.baseSlectedModel];
            }
            //分组后的封装保存到baseWfModel供其他使用
            weakSelf.baseWFmodel.baseSelectedModel = weakSelf.selectedArrary;
            
            if ([weakSelf.baseWFmodel.mutex isEqualToString:@"1"]) {/**胆拖上下互斥玩法*/
                
                [weakSelf dantuoWFMetuxWithCell:weakcell];
                
            }else if ([weakSelf.baseWFmodel.mutex isEqualToString:@"3"]){//【021需求】腾讯分分彩 台湾五分彩 北京时时彩 大小单双 只能混合投注
                [weakSelf daXiaoDanShuang_HunHeTouZhu:weakcell];
            }
            MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:weakSelf.baseWFmodel];
           
           if (arr.count != 0 || weakSelf.clearAllNumber == YES) {
                [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
            }
            
        };
        
    }else{
        
    }
    cell.baseWFmodel = self.baseWFmodel;
    if (self.randomBallArray.count != 0) {
        cell.randomNumber = self.randomBallArray[indexPath.row];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return  self.baseWFmodel.lineH;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.view endEditing:YES];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return _height_Footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 0.00001;
}
//- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//
//    return  self.view_selectedCard;
//    
//}
#pragma mark-修改tableView 的 Footer高度
- (void)mcTableView_height:(NSNotification *)noti{
    
    NSDictionary *dic = noti.userInfo;
    int isShowFooter = [dic[@"isShowFooter"] intValue];
    if (isShowFooter) {
        _height_Footer=(146-49);
    }else{
        _height_Footer=0.0001;
    }
    self.view_footer.frame=CGRectMake(0, 0, G_SCREENWIDTH, _height_Footer);
    [self.baseTableView setTableFooterView:self.view_footer];

}

#pragma mark-点击近期开奖
-(void)KaiJiangClick{
    __weak typeof(self) weakSelf = self;
    MCLotteryRecordViewController *VC = [[MCLotteryRecordViewController alloc]init];
    VC.LotteryCode=self.baseWFmodel.LotteryID;
    VC.recordGoBackBlock = ^(NSString *fromClass, NSString *LotteryCode) {
        MCLotteryDrawDetailsViewController * vc = [[MCLotteryDrawDetailsViewController alloc]init];
        vc.fromClass=NSStringFromClass([MCPickNumberViewController class]);
        vc.LotteryCode=self.baseWFmodel.LotteryID;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    MCPullMenuPresentationController *PC = [[MCPullMenuPresentationController alloc] initWithPresentedViewController:VC presentingViewController:self];
    PC.type=MCPullMenuKaiJiangType;
    PC.goBackBlock = ^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    };
    VC.transitioningDelegate = PC;
    [self presentViewController:VC animated:YES completion:NULL];
}


#pragma mark -Custem Method
/**胆拖上下互斥玩法*/
- (void)dantuoWFMetuxWithCell:(MCLotteryHalllPickTableViewCell *)cell{
    
    if (self.selectedArrary.count >=2) {
        MCBaseSelectedModel *model1 = self.selectedArrary[0];
        MCBaseSelectedModel *model2 = self.selectedArrary [1];
        [model1.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj1, NSUInteger idx, BOOL * _Nonnull stop) {
            [model2.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj2, NSUInteger idx, BOOL * _Nonnull stop) {
                NSString *str1 = obj1;
                NSString *str2 = obj2;
                if ([self.baseWFmodel.tongxuan isEqualToString:@"2"]) {
                    if ([self.baseWFmodel.lotteryCategories isEqualToString:@"k3"]) {
                    str1 = [NSString stringWithFormat:@"%@",[obj1 substringWithRange:NSMakeRange(0, 1)]];
                    str2 = [NSString stringWithFormat:@"%@",[obj2 substringWithRange:NSMakeRange(0, 1)]];
                    }else{
                    str1 = [NSString stringWithFormat:@"0%@",[obj1 substringWithRange:NSMakeRange(0, 1)]];
                    }
                }
                if ([str1 isEqualToString:str2] ) {
                    if (![self.baseWFmodel.lotteryCategories isEqualToString:@"k3"]) {
                    MCLotteryHalllPickTableViewCell *cell1 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model1.index inSection:0]];
                    MCLotteryHalllPickTableViewCell *cell2 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model2.index inSection:0]];
                    if (cell == cell2) {
                        for (MCBallCollectionModel*model in cell1.ballArray) {
                            if ([obj1 isEqualToString:model.textInfo]) {
                                model.seleted = NO;
                            }
                            [model1.selectedArray removeObject:obj1];
                        }
                        [cell1.ballColletionView reloadData];
                    } else {
                        for (MCBallCollectionModel*model in cell2.ballArray) {
                            if ([str1 isEqualToString:model.textInfo]) {
                                model.seleted = NO;
                            }
                            [model2.selectedArray removeObject:obj1];
                        }
                        [cell2.ballColletionView reloadData];
                    }
                    }else{
                        MCLotteryHalllPickTableViewCell *cell1 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model1.index inSection:0]];
                        MCLotteryHalllPickTableViewCell *cell2 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model2.index inSection:0]];
                        if (cell == cell2) {
                            for (MCBallCollectionModel*model in cell1.ballArray) {
                                if ([str1 isEqualToString:[NSString stringWithFormat:@"%@",[model.textInfo substringWithRange:NSMakeRange(0, 1)]]]) {
                                    model.seleted = NO;
                                }
                                [model1.selectedArray removeObject:obj1];
                            }
                            [cell1.ballColletionView reloadData];
                        } else {
                            for (MCBallCollectionModel*model in cell2.ballArray) {
                                if ([str1 isEqualToString:[NSString stringWithFormat:@"%@",[model.textInfo substringWithRange:NSMakeRange(0, 1)]]]) {
                                    model.seleted = NO;
                                }
                                [model2.selectedArray removeObject:obj2];
                            }
                            [cell2.ballColletionView reloadData];
                        }
                    }
                }
            }];
        }];
    }
}

#pragma mark-【021需求】腾讯分分彩 台湾五分彩 北京时时彩 大小单双 只能混合投注
-(void)daXiaoDanShuang_HunHeTouZhu:(MCLotteryHalllPickTableViewCell *)cell{
    MCBaseSelectedModel *model1,*model2,*model3;
    
    if ([self.baseWFmodel.name isEqualToString:@"后三"]||[self.baseWFmodel.name isEqualToString:@"前三"]){
        if (self.selectedArrary.count >2) {
            model1 = self.selectedArrary[0];
            model2 = self.selectedArrary [1];
            model3 = self.selectedArrary [2];
            [model1.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj1, NSUInteger idx, BOOL * _Nonnull stop) {
                [model2.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj2, NSUInteger idx, BOOL * _Nonnull stop) {
                        [model3.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj3, NSUInteger idx, BOOL * _Nonnull stop) {
                            NSString *str1 = obj1;
                            NSString *str2 = obj2;
                            NSString *str3 = obj3;
                            if ([str1 isEqualToString:str2] &&[str1 isEqualToString:str3]) {
                                MCLotteryHalllPickTableViewCell *cell1 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model1.index inSection:0]];
                                MCLotteryHalllPickTableViewCell *cell2 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model2.index inSection:0]];
                                MCLotteryHalllPickTableViewCell *cell3 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model3.index inSection:0]];
                                if (cell1==cell) {
                                    for (MCBallCollectionModel*model in cell1.ballArray) {
                                        if ([str1 isEqualToString:model.textInfo]) {
                                            model.seleted = NO;
                                        }
                                        [model1.selectedArray removeObject:obj1];
                                    }
                                    [cell1.ballColletionView reloadData];
                                    [SVProgressHUD showInfoWithStatus:@"该玩法只能混合购买"];
                                }else if(cell2==cell){
                                    for (MCBallCollectionModel*model in cell2.ballArray) {
                                        if ([str2 isEqualToString:model.textInfo]) {
                                            model.seleted = NO;
                                        }
                                        [model2.selectedArray removeObject:obj2];
                                    }
                                    [cell2.ballColletionView reloadData];
                                    [SVProgressHUD showInfoWithStatus:@"该玩法只能混合购买"];
                                }else if(cell3==cell){
                                    for (MCBallCollectionModel*model in cell3.ballArray) {
                                        if ([str3 isEqualToString:model.textInfo]) {
                                            model.seleted = NO;
                                        }
                                        [model3.selectedArray removeObject:obj3];
                                    }
                                    [cell3.ballColletionView reloadData];
                                    [SVProgressHUD showInfoWithStatus:@"该玩法只能混合购买"];
                                }
                            }
                        }];
                }];
            }];
        }
    }else{
        if (self.selectedArrary.count >=2) {
            model1 = self.selectedArrary[0];
            model2 = self.selectedArrary [1];
            [model1.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj1, NSUInteger idx, BOOL * _Nonnull stop) {
                [model2.selectedArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj2, NSUInteger idx, BOOL * _Nonnull stop) {
                    NSString *str1 = obj1;
                    NSString *str2 = obj2;
                    if ([str1 isEqualToString:str2] ) {
                        
                        MCLotteryHalllPickTableViewCell *cell1 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model1.index inSection:0]];
                        MCLotteryHalllPickTableViewCell *cell2 = [self.baseTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:model2.index inSection:0]];
                        if (cell == cell2) {
                            for (MCBallCollectionModel*model in cell1.ballArray) {
                                if ([obj1 isEqualToString:model.textInfo]) {
                                    model.seleted = NO;
                                }
                                [model1.selectedArray removeObject:obj1];
                            }
                            [cell1.ballColletionView reloadData];
                        } else {
                            for (MCBallCollectionModel*model in cell2.ballArray) {
                                if ([str1 isEqualToString:model.textInfo]) {
                                    model.seleted = NO;
                                }
                                [model2.selectedArray removeObject:obj1];
                            }
                            [cell2.ballColletionView reloadData];
                        }
                    }
                }];
            }];
        }
    }
}

- (NSMutableArray *)setNumberSelectedArray{
    
    NSMutableArray *allNumberArray = [NSMutableArray array];
    
    for (NSInteger i = 0; i<self.baseWFmodel.item.count; i++) {
        NSMutableArray *sectionArray = [NSMutableArray array];
        MCLotteryHalllPickTableViewCell *cell = self.cellArray[i];
        for (MCBallCollectionModel *model in cell.ballArray) {
            if (model.seleted == YES) {
                [sectionArray addObject:model];
            }
        }
        if (sectionArray.count != 0) {
            [allNumberArray addObject:sectionArray];
        }
        
    }
    
    return  allNumberArray;
}
/**夫类方法*/
#pragma mark ----------------------------- 重写父类方法
#pragma mark-机选
- (void)randomBtnClick{
    [super randomBtnClick];
    
    
    [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"JIXUAN"];
    for (NSInteger i = 0; i<self.baseWFmodel.item.count; i++) {
        MCLotteryHalllPickTableViewCell *cell = self.cellArray[i];
        for (MCBallCollectionModel *model in cell.ballArray) {
            model.seleted = NO;
        }
        [cell.selectedBallArray removeAllObjects];
        [cell.ballColletionView reloadData];
    }

    [self.baseWFmodel.baseSelectedModel removeAllObjects];
    NSMutableArray *arr = [MCRandomUntits Get_RandomArrWithModel:self.baseWFmodel];
    if (arr.count != self.cellArray.count) {return;}
    for (NSInteger i = 0; i<arr.count; i++) {
        MCLotteryHalllPickTableViewCell *cell = self.cellArray[i];
        for (MCBallCollectionModel *model in cell.ballArray) {
            model.seleted = NO;
        }
        NSMutableArray *randomNumber = arr[i];
        for (NSInteger j = 0; j<randomNumber.count; j++) {
            NSString *str = randomNumber[j];
            for (MCBallCollectionModel *model in cell.ballArray) {
                if ([str isEqualToString:model.textInfo]) {
                    model.seleted = YES;
                }
            }
        }
    }
    [self.baseTableView reloadData];
    
    for (NSInteger i = 0; i<arr.count; i++) {
        MCLotteryHalllPickTableViewCell *cell = self.cellArray[i];
        [cell.ballColletionView reloadData];
    }
    
}


#pragma mark-清
- (void)clearAllButtonClick{
    self.clearAllNumber = YES;
    [self clearData];
}

- (void)clearData{
    self.baseWFmodel.stakeNumber=0;
    //单式清除操作
    if ([self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {

        MCLotteryHalllPickTableViewCell *cell=[self.baseTableView  cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

        [cell danShiClear];
        self.baseWFmodel.danShiArray=nil;
        MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
        [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
    }else{
        if (self.baseWFmodel.item.count == 0) {
            return;
        }
        
        for (NSInteger i = 0; i<self.baseWFmodel.item.count; i++) {
            if (self.cellArray.count > i) {
                MCLotteryHalllPickTableViewCell *cell = self.cellArray[i];
                for (MCBallCollectionModel *model in cell.ballArray) {
                    model.seleted = NO;
                }
                [cell.selectedBallArray removeAllObjects];
                [cell.ballColletionView reloadData];
            }

        }
    }
}
#pragma mark-添加号码
- (void)addNumberToShoppingCar:(BOOL)isShow{
    self.danQiNotiShowed = YES;
    [self addNumber:isShow];
}

- (void)danqiNode{
    
    int mode = [self.baseWFmodel.Mode intValue];
    if ((mode & 64) == 64) {//单挑功能
        for (MCMaxbonusModel *model in self.boModelArray) {
            if ([model.Sign isEqualToString:@"2"]) {
                continue;
            }
          NSString *strid =  [NSString stringWithFormat:@"%@%@",self.baseWFmodel.LotteryID,self.baseWFmodel.methodId];
            if ( [model.PlayCode isEqualToString:strid]) {
                if([model.SoloNote intValue] >= self.baseWFmodel.stakeNumber){
                       NSString *strinfo = @"";
               
                    strinfo = [NSString stringWithFormat:@"您所投注内容为单挑玩法，最高奖金为%@元",GetRealSNum(model.SoloAmt)];
                    
                    [SVProgressHUD showInfoWithStatus:strinfo];
                    
                }
            }
        }
    }
}

#pragma mark-快速投注
- (void)conferencePayTheSelectedNumbers{
    
    
   
    
    if (![MCDataTool isCanTouZhu]) {
        [SVProgressHUD showInfoWithStatus:@"您的账号不允许投注"];
        return;
    }
    
    if (!self.baseWFmodel.userSelectedRebate) {
        [SVProgressHUD showInfoWithStatus:@"返点获取失败！"];
        return;
    }
    
    if (![self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
        if (self.IssueNumber.length<1) {
            [SVProgressHUD showInfoWithStatus:@"期号获取失败！"];
            return;
        }
    }
   
    
    /*
     * 单式
     */
    if ([self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {
//        MCLotteryHalllPickTableViewCell *cell=[self.baseTableView  cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        
        MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
        [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
        if (self.isDanShi) {
        }else{
            [self.alertView hideStackWindow];
        }
        
        if (self.baseWFmodel.stakeNumber<1) {
            [SVProgressHUD showInfoWithStatus:@"请至少选择一注号码！"];
            return;
        }
        
    }
    
    //如果 当前角标为0  用户选择的球  够一注   也可以投注
    int minStakeNumber=1;
    if ([self.baseWFmodel.isDanTuo isEqualToString:@"1"]) {
        minStakeNumber=2;
    }

    
    if (self.baseWFmodel.stakeNumber>=minStakeNumber) {

//        if ((self.baseWFmodel.payMoney+0.001)<0.02) {
//            [SVProgressHUD showErrorWithStatus:@"厘模式每单最少投注0.02元"];
//            return;
//        }
        double MinBetMoney= [[[NSUserDefaults standardUserDefaults] objectForKey:MCMinBetMoney] doubleValue];
        if ((self.baseWFmodel.payMoney+0.001)<MinBetMoney) {
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"每单最少投注%@元",GetRealFloatNum(MinBetMoney)]];
            return;
        }
    }
    
    if (self.baseWFmodel.stakeNumber<minStakeNumber&&self.baseWFmodel.danShiArray.count<1) {
        if (minStakeNumber==2) {
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"请至少选择两注号码！"]];
            return;
        }
        [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"请至少选择一注号码！"]];
        return;
    }
    if (self.isRequsting == NO) {
        self.requsting = YES;
        [self pop];
    }
    
    
 
    
}

- (void)pop{
    
    //秒秒彩
    if ([self.baseWFmodel.czName containsString:@"秒秒彩"]) {
        
        [self goToRunLotteryImmediately];
        
        //非秒秒彩
    }else{
        
        [self lottery_bet];
        
    }
}
- (void)pop2RefirmView{
    
 
    MCPaySelectedCellModel * Smodel = [MCMathUnits GetFormatWithWFModel:self.baseWFmodel];
    NSString *sMode = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:MerchantMode]];
    
    int mode = [sMode intValue];
    NSString *maxstr = @"";
    if ((mode & 128) == 128) {//单期功能
        for (MCMaxbonusModel *model in self.boModelArray) {
            
            if ([model.SingleStageCode isEqualToString:self.baseWFmodel.LotteryID]) {
                maxstr = model.MaxAmt;
            }else{
                continue ;
            }
            
        }
    }
    NSString * tip;
    if (maxstr.length>1) {
        tip =[NSString stringWithFormat:@"您共投%@注，共%@元\n该彩种单期最高奖金为%@元,请确认",Smodel.stakeNumber,GetRealSNum(Smodel.payMoney),GetRealSNum(maxstr )];
    }else{
        tip=[NSString stringWithFormat:@"您共投%@注，共%@元，请确认",Smodel.stakeNumber,GetRealSNum(Smodel.payMoney)];
    }
    
    
    MCPopAlertView *mcAlertView = [[MCPopAlertView alloc] initWithType:MCPopAlertTypeTZRequest_Confirm Title:@"投注确认" message:tip leftBtn:@"确认投注" rightBtn:@"取消返回"];
    
    mcAlertView.resultIndex = ^(NSInteger index){
        if (index==1) {
    
        [self lottery_bet];
            
        }
    };
    [mcAlertView showXLAlertView];


   
}
#pragma mark-秒秒彩-立即开奖
-(void)goToRunLotteryImmediately{


//    [];
    
    MCPaySelectedCellModel * Smodel = [MCMathUnits GetFormatWithWFModel:self.baseWFmodel];
    
    MCUserMoneyModel * money_model=[MCUserMoneyModel sharedMCUserMoneyModel];
    NSString * LotteryMoney = [NSString stringWithFormat:@"%@",money_model.LotteryMoney];
    if ([Smodel.payMoney floatValue]>[LotteryMoney floatValue]) {
        [SVProgressHUD showInfoWithStatus:@"余额不足!"];
        return;
    }
    
    NSMutableArray * betMarr=[[NSMutableArray alloc]init];
    NSString * BetRebate=@"";
    

    if (Smodel.BetRebate) {
            BetRebate=Smodel.BetRebate;
        }
        NSDictionary * betDic = @{
                                  @"BetContent":Smodel.tz_haoMa,//投注内容
                                  @"BetCount":Smodel.stakeNumber,//投注注数
                                  @"PlayCode":Smodel.PlayCode,//玩法编码
                                  @"BetRebate":BetRebate,//投注返点
                                  @"BetMoney":Smodel.payMoney,//投注金额
                                  @"BetMultiple":Smodel.multiple,//投注倍数
                                  @"BetMode":Smodel.BetMode//玩法模式
                                  };
        [betMarr addObject:betDic];

    
    NSDictionary * dic =@{
                          @"UserBetInfo":@{
                                  @"LotteryCode":self.baseWFmodel.LotteryID,//彩种编码
                                  @"Bet":betMarr
                                  }
                          
                          };
    __weak __typeof__ (self) wself = self;
    
    
    MCMMCNewViewController *VC = [[MCMMCNewViewController alloc]init];
    VC.mmcGoBackBlock = ^{
        
        //投注成功要做的事情
        //清空单例
//        MCPaySLBaseModel * dataSourceModel = [MCPaySLBaseModel sharedMCPaySLBaseModel];
//        [dataSourceModel removeDataSource];
//        wself.addItemLabel.hidden = YES;
//        wself.addItemLabel.text = @"";
        [wself clearAllButtonClick];
        //2.刷新余额
        [wself refreashUserMoney];
        //3.刷新开奖
        __weak typeof(self) weakSelf = self;
        MCLotteryRecordViewController * VC = [[MCLotteryRecordViewController alloc]init];
        VC.LotteryCode=self.baseWFmodel.LotteryID;
        [VC getRecord:^(BOOL result, NSArray *firstDataSource, id manager) {
            
            if (result&&firstDataSource.count>0) {
                weakSelf.historyView.lastHistoryBallArray=firstDataSource;
                weakSelf.noDatalabel.hidden = YES;
            }else{
                weakSelf.noDatalabel.hidden = NO;
            }
        }];

    };
    VC.dic=dic;
    VC.lianKaiCount=1;//连开次数
    MCMMCPresentationController *PC = [[MCMMCPresentationController alloc] initWithPresentedViewController:VC presentingViewController:self];
    VC.transitioningDelegate = PC;
    [self presentViewController:VC animated:YES completion:NULL];
    
    
}


#pragma mark-非秒秒彩投注
-(void)lottery_bet{
    
    
    NSMutableArray * betMarr=[[NSMutableArray alloc]init];
    __weak __typeof__ (self) wself = self;
    MCPaySelectedCellModel * Smodel = [MCMathUnits GetFormatWithWFModel:self.baseWFmodel];
    MCUserMoneyModel * money_model=[MCUserMoneyModel sharedMCUserMoneyModel];
    NSString * LotteryMoney = [NSString stringWithFormat:@"%@",money_model.LotteryMoney];
    if ([Smodel.payMoney floatValue]>[LotteryMoney floatValue]) {
        [SVProgressHUD showInfoWithStatus:@"余额不足!"];
        return;
    }

    if (!Smodel.BetRebate) {
            [SVProgressHUD showInfoWithStatus:@"返点为空，请返回重新选择！"];
            return;
        }
        NSDictionary * betDic = @{
                                  @"BetContent":Smodel.tz_haoMa,//投注内容
                                  @"BetCount":Smodel.stakeNumber,//投注注数
                                  @"PlayCode":Smodel.PlayCode,//玩法编码
                                  @"IssueNumber":self.IssueNumber,//投注期号
                                  @"BetRebate":Smodel.BetRebate,//投注返点
                                  @"BetMoney":Smodel.payMoney,//投注金额
                                  @"BetMultiple":Smodel.multiple,//投注倍数
                                  @"BetMode":Smodel.BetMode//玩法模式
                                  };
        [betMarr addObject:betDic];

    NSDictionary * dic =@{
                          @"UserBetInfo":@{
                                  @"LotteryCode":self.baseWFmodel.LotteryID,//彩种编码
                                  @"Bet":betMarr
                                  }
                          };
    
    MCBetModel *betModel = [[MCBetModel alloc] initWithDic:dic];
    self.betModel=betModel;

    [betModel refreashDataAndShow];
    betModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        wself.requsting = NO;
        NSString * sCode = [NSString stringWithFormat:@"%@",errorCode];
        if ([sCode containsString:@"410"]||[sCode containsString:@"400"]) {
            NSString * responseMessage=[NSString stringWithFormat:@"%@",manager.responseMessage];
            [SVProgressHUD showInfoWithStatus:responseMessage];
        }
    };
    betModel.callBackSuccessBlock = ^(id manager) {
        //投注成功要做的事情
        [wself betSuccessToDo];
        
    };
    
}

#pragma mark-投注【成功】后要做的事情
-(void)betSuccessToDo{
    //1.清空单例
//    MCPaySLBaseModel * dataSourceModel = [MCPaySLBaseModel sharedMCPaySLBaseModel];
//    [dataSourceModel removeDataSource];
//    self.addItemLabel.hidden = YES;
//    self.addItemLabel.text = @"";
    self.baseWFmodel.stakeNumber=0;
    [self clearAllButtonClick];
    //2.刷新余额
    [self refreashUserMoney];
    //3.刷新开奖
    __weak typeof(self) weakSelf = self;
    MCLotteryRecordViewController * VC = [[MCLotteryRecordViewController alloc]init];
    VC.LotteryCode=self.baseWFmodel.LotteryID;
    [VC getRecord:^(BOOL result, NSArray *firstDataSource, id manager) {
        
        if (result&&firstDataSource.count>0) {
            weakSelf.historyView.lastHistoryBallArray=firstDataSource;
            weakSelf.noDatalabel.hidden = YES;
        }else{
            weakSelf.noDatalabel.hidden = NO;
        }
    }];
    [self clearAllButtonClick];
    
    MCPopAlertView *mcAlertView = [[MCPopAlertView alloc] initWithType:MCPopAlertTypeTZRequest_Success Title:@"投注确认" message:@"投注成功" leftBtn:@"继续投注" rightBtn:@"查看记录"];
    
    mcAlertView.resultIndex = ^(NSInteger index){
        //回调---处理一系列动作x
#pragma mark-查看记录
        if (index==2) {
            
            //获得视图控制器堆栈数组
            NSArray *currentControllers = weakSelf.navigationController.viewControllers;
            //基于堆栈数组实例化新的数组
            NSMutableArray *newControllers = [NSMutableArray arrayWithArray:currentControllers];
            
            MCGameRecordViewController * vc = [[MCGameRecordViewController alloc]init];
            
            UIViewController * pVC=[newControllers lastObject];
            
            weakSelf.navigationController.navigationBar.tintColor = [UIColor whiteColor];
            
            [UIView animateWithDuration:0.001 animations:^{
                //为堆栈重新赋值
                [weakSelf.navigationController setViewControllers:newControllers animated:NO];
            } completion:^(BOOL finished) {
                [pVC.navigationController pushViewController:vc animated:YES];
            }];
            
#pragma mark-继续投注
        }else if (index==1){
            
        }
        
    };
    [mcAlertView showXLAlertView];
}

#pragma mark-去投注
- (void)payTheSelectedNumbers{
    
    MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
    if (model.dataSource.count<1) {
         [SVProgressHUD showInfoWithStatus:@"请至少选择一注号码！"];
        return;
    }
    if (!self.baseWFmodel.userSelectedRebate) {
        [SVProgressHUD showInfoWithStatus:@"返点获取失败！"];
        return;
    }
    if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
    }else{
        if (self.IssueNumber.length<1) {
            [SVProgressHUD showInfoWithStatus:@"期号获取失败！"];
            return;
        }
    }
    
    int stakeNumber = self.baseWFmodel.stakeNumber;
    MCPaySelectedLotteryTableViewController *vc =  [[MCPaySelectedLotteryTableViewController alloc] init];
    vc.boModelArray = self.boModelArray;
    MCBasePWFModel *baseWFmodel = [[MCBasePWFModel alloc]init];
    baseWFmodel = self.baseWFmodel;
    baseWFmodel.stakeNumber = stakeNumber;
    vc.baseWFmodel = baseWFmodel;
    vc.RemainTime=self.time;
    vc.IssueNumber=self.IssueNumber;
    vc.betRebateArray = self.betRebateArray;
    vc.danQiNotiShowed = self.danQiNotiShowed;
    vc.stakeNumber=stakeNumber;
    vc.isHadChanged=_isHadChanged;
    [self.navigationController pushViewController:vc animated:YES];
    [self clearAllButtonClick];

    
}

- (void) dan{
    
    if (self.baseWFmodel.stakeNumber==0) {
        MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
        
        
        [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
    }
    
    MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
    [model addDataSourceWithModel:self.baseWFmodel];
    self.addItemLabel.hidden=NO;
    self.addItemLabel.text = [NSString stringWithFormat:@"%d",(int)model.dataSource.count];
    
    [self clearAllButtonClick];
    if (self.isDanShi) {
    }else{
        [self.alertView hideStackWindow];
    }
}
- (void) danShiAddNumber:(MCLotteryHalllPickTableViewCell *)cell{
    
    /*
     * 加入数据
     */
    if (self.baseWFmodel.stakeNumber==0) {
        MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
        
        
        [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
    }
    
    MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
    [model addDataSourceWithModel:self.baseWFmodel];
    _isHadChanged=YES;
    self.addItemLabel.hidden=NO;
    self.addItemLabel.text = [NSString stringWithFormat:@"%d",(int)model.dataSource.count];
    
    [self clearAllButtonClick];
    if (self.isDanShi) {
    }else{
        [self.alertView hideStackWindow];
    }
    cell.AModel=nil;
}
- (void) addNumber:(BOOL)isShow{
    if (!self.baseWFmodel.userSelectedRebate) {
        [SVProgressHUD showInfoWithStatus:@"返点获取失败！"];
        return;
    }
    if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
    }else{
        if (self.IssueNumber.length<1) {
            [SVProgressHUD showInfoWithStatus:@"期号获取失败！"];
            return;
        }
    }
    //秒秒彩 秒秒彩限制最多一次添加10单
    if([self.baseWFmodel.LotteryID isEqualToString:@"50"]){
        MCPaySLBaseModel * DDDmodel=[MCPaySLBaseModel sharedMCPaySLBaseModel];
        if(DDDmodel.dataSource.count>9){
            [SVProgressHUD showInfoWithStatus:@"秒秒彩限制最多一次添加10单！"];
            return;
        }
    }
    int minStakeNumber=1;
    if ([self.baseWFmodel.isDanTuo isEqualToString:@"1"]) {
        minStakeNumber=2;
    }
    if (self.baseWFmodel.stakeNumber > 0) {
        [self danqiNode];
    }
    double MinBetMoney= [[[NSUserDefaults standardUserDefaults] objectForKey:MCMinBetMoney] doubleValue];

    if (isShow) {
            if ((self.baseWFmodel.payMoney+0.001)<MinBetMoney) {
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"每单最少投注%@元",GetRealFloatNum(MinBetMoney)]];
                return;
            }
    }
    

    //厘模式   >=0.02
    if ((self.baseWFmodel.payMoney+0.001)<MinBetMoney) {
        if (isShow) {
//            [SVProgressHUD showErrorWithStatus:@"厘模式每单最少投注0.02元"];
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"每单最少投注%@元",GetRealFloatNum(MinBetMoney)]];
        }
    }else{
        //单式添加号码
        if ([self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {
            MCLotteryHalllPickTableViewCell *cell=[self.baseTableView  cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
            //已经校验过了   并且  文本框没有被修改
            if ([cell.lastNumberString isEqualToString:cell.mcTextView.text] && cell.AModel.Do_Wrong && cell.lastNumberString.length>0 && cell.AModel.arr_Result.count>0) {
                [self danShiAddNumber:cell];
            }else{
                MCArryModel*Amodel= [cell delWrongNumber:NO];
                if (Amodel.Do_Wrong&&Amodel.arr_Result.count>0) {
                    if (self.baseWFmodel.stakeNumber==0) {
                        MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
                        [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
                    }
                    MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
                    [model addDataSourceWithModel:self.baseWFmodel];
                    _isHadChanged=YES;
                    self.addItemLabel.hidden=NO;
                    self.addItemLabel.text = [NSString stringWithFormat:@"%d",(int)model.dataSource.count];
                    
                    [self clearAllButtonClick];
                    if (self.isDanShi) {
                    }else{
                        [self.alertView hideStackWindow];
                    }
                }else{
                    if (Amodel.arr_Wrong.count>0) {
                        return;//此时会弹出去错误号码的框  不需要再弹出了
                    }
                    [SVProgressHUD showInfoWithStatus:@"请至少选择一注号码！"];
                }
                cell.AModel=nil;
            }
            
        }else{
            MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
            if (self.baseWFmodel.stakeNumber>=minStakeNumber) {
                [model addDataSourceWithModel:self.baseWFmodel];
                _isHadChanged=YES;
                self.addItemLabel.hidden=NO;
                self.addItemLabel.text = [NSString stringWithFormat:@"%d",(int)model.dataSource.count];
                [self clearAllButtonClick];
            }else{
                if(model.dataSource.count == 0||self.baseWFmodel.stakeNumber<minStakeNumber){
                    if (isShow) {
                        if (minStakeNumber==2) {
                            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"请至少选择两注号码！"]];
                        }else{
                            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"请至少选择一注号码！"]];
                        }
                    }
                    return;
                }
            }
            
        }
        
    }
}
#pragma mark - getter and setter



- (NSMutableArray *)cellArray{
    if (_cellArray== nil) {
        _cellArray = [NSMutableArray array];
    }
    return _cellArray;
}


- (NSMutableArray *)randomBallArray{
    if (_randomBallArray == nil) {
        _randomBallArray = [NSMutableArray array];
    }
    return _randomBallArray;
}

- (NSMutableArray *)selectedArrary{
    if (_selectedArrary == nil) {
        _selectedArrary = [NSMutableArray array];
    }
    return _selectedArrary;
}

-(UIView *)view_footer{
    if (!_view_footer) {
        _view_footer=[[UIView alloc]init];
        _view_footer.backgroundColor=[UIColor clearColor];
    }
    return _view_footer;
}

- (void)setBaseWFmodel:(MCBasePWFModel *)baseWFmodel{
    
    [super setBaseWFmodel:baseWFmodel];
    self.clearAllNumber = NO;
    baseWFmodel.lotteryCategories = self.lotteriesTypeModel.type;
    if ([baseWFmodel.filterCriteria isEqualToString:@"2"]) {

            self.baseTableView.frame = CGRectMake(0, HEIGHTDAOJISHI+HEIGHTKAIJIANGHAO, G_SCREENWIDTH, G_SCREENHEIGHT - (HEIGHTDAOJISHI+HEIGHTKAIJIANGHAO)-49-44);
        
    } else {

            self.baseTableView.frame = CGRectMake(0, HEIGHTDAOJISHI+HEIGHTKAIJIANGHAO, G_SCREENWIDTH, G_SCREENHEIGHT - (HEIGHTDAOJISHI+HEIGHTKAIJIANGHAO)- 49-44);
        
    }
    if (@available(iOS 11.0, *)) {
        if (self.baseWFmodel.lineH *[self.baseWFmodel.lineCount intValue] >= G_SCREENHEIGHT - 64 - 40 - MC_REALVALUE(40) - 69 - 20 ) {
            self.baseTableView.contentInset = UIEdgeInsetsMake(40, 0, 20, 0);
        } else {
            if (![self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {
                self.baseTableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
            }
        }
        
    }else{
        self.baseTableView.contentInset = UIEdgeInsetsMake(MC_REALVALUE(40), 0, 20, 0);
    }
    [self.cellArray removeAllObjects];
    [self.randomBallArray removeAllObjects];
    
    for (MCBaseSelectedModel *model in self.selectedArrary) {
        
        [model.selectedArray removeAllObjects];
    }
    [self.selectedArrary removeAllObjects];
    
    [self.baseTableView reloadData];
    
    
}

#pragma mark-刷新余额
-(void)refreashUserMoney{
    __weak typeof(self) weakSelf = self;
    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
    
    [userMoneyModel refreashDataAndShow];
    self.userMoneyModel=userMoneyModel;
    
    userMoneyModel.callBackSuccessBlock = ^(id manager) {
        weakSelf.requsting = NO;
        weakSelf.userMoneyModel.FreezeMoney=manager[@"FreezeMoney"];
        weakSelf.userMoneyModel.LotteryMoney=manager[@"LotteryMoney"];
        
        weakSelf.labelBonusDetail.attributedText =[NSString attrbutstring:[NSString stringWithFormat:@"余额:%@",[MCMathUnits GetMoneyShowNum:[MCUserMoneyModel sharedMCUserMoneyModel].LotteryMoney]]];
        
    };

}

@end
